package com.zline.foodraise.util;

import org.androidannotations.annotations.EBean;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

/**
 * Created by heshantao on 15/10/15.
 * 时间工具类
 */
@EBean
public class TimeUtil {
    private static final String LOG_TAG = TimeUtil.class.getSimpleName();

    //判断时间戳是否为今天
   public boolean isToday(long timeStamp) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(timeStamp * 1000);
        int year = calendar.get(Calendar.YEAR);
        int month = calendar.get(Calendar.MONTH) + 1;
        int day = calendar.get(Calendar.DAY_OF_MONTH);
        calendar.setTimeInMillis(System.currentTimeMillis());
        int nowYear = calendar.get(Calendar.YEAR);
        int nowMonth = calendar.get(Calendar.MONTH) + 1;
        int nowDay = calendar.get(Calendar.DAY_OF_MONTH);
        return (year == nowYear)
                && (month == nowMonth)
                && (day == nowDay);
    }

    //将时间戳转化为日期格式
    public String formatData(long timeStamp) {
        String result = "";
        String dataFormat = "MM月dd日 HH:mm";
        if (timeStamp == 0) {
            return "";
        }
        timeStamp = timeStamp * 1000;
        SimpleDateFormat format = new SimpleDateFormat(dataFormat, Locale.getDefault());
        result = format.format(new Date(timeStamp));
        return result;
    }

    //将时间戳转化为日期格式横杠
    public String formatData2(long timeStamp) {
        String dataFormat = "MM-dd HH:mm";
        if (timeStamp == 0) {
            return "";
        }
        timeStamp = timeStamp * 1000;
        String result = "";
        SimpleDateFormat format = new SimpleDateFormat(dataFormat, Locale.getDefault());
        result = format.format(new Date(timeStamp));
        return result;
    }

    //将时间戳转化为日期格式
    public String formatData3(long timeStamp) {
        String dataFormat = "yyyy-MM-dd HH:mm:ss";
        if (timeStamp == 0) {
            return "";
        }
        timeStamp = timeStamp * 1000;
        String result = "";
        SimpleDateFormat format = new SimpleDateFormat(dataFormat, Locale.getDefault());
        result = format.format(new Date(timeStamp));
        return result;
    }


    //将时间戳转化为日期格式横杠
    public String formatData4(long timeStamp) {
        String dataFormat = "yyyy-MM-dd";
        if (timeStamp == 0) {
            return "";
        }
        timeStamp = timeStamp * 1000;
        String result = "";
        SimpleDateFormat format = new SimpleDateFormat(dataFormat, Locale.getDefault());
        result = format.format(new Date(timeStamp));
        return result;
    }

    //将时间戳转化为小时和时间
    public String formatHourAndMin(long timeStamp) {
        String dataFormat = "HH:mm";
        if (timeStamp == 0) {
            return "";
        }
        timeStamp = timeStamp * 1000;
        String result = "";
        SimpleDateFormat format = new SimpleDateFormat(dataFormat, Locale.getDefault());
        result = format.format(new Date(timeStamp));
        return result;
    }


}
